package Java道题;

import java.util.Scanner;

public class 求斐波那契数非递归 {
	//求斐波那契数列 1,1,2,3,5...
	/*		{F(n-1)+F(n-2) n>2		 }
	 * F(n)={1	 		   n==1||n==2}
	 *
	 */
	public static double cal(int n)
	{
		/*double num = 0;
		double tmp = 0;
		double temp = 0;
		for(int i=1;i<=n;i++)
		{
			if(i==1||i==2)
			{
				tmp=1;
				temp=1;
				num=1;
			}
			else
			{
			num=tmp+temp;//可用数组代替，可读性更好
			tmp=temp;
			temp=num;
			}
		}
		return num;*/
		int[] arr=new int[n];
		int i;
		for(i=0;i<n;i++)
		{
			if(i==0||i==1)
			{
				arr[i]=1;
			}
			else
			{
				arr[i]=arr[i-1]+arr[i-2];
			}
		}
		//return arr[i];
		return arr[n-1];
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner ss=new Scanner(System.in);

		System.out.print("请输入n:");
		int n=ss.nextInt();
		System.out.println("第"+n+"个数为： "+cal(n));



	}

}
